package com.fizzbuzz;

public class FizzBuzz {
    private int number;
    public FizzBuzz(int number) {
        if (number < 1 || number > 100){
            throw new IllegalArgumentException();
        }
        this.number = number;
    }

    public String fizzBuzz() {
        String result = "";
        if (timesNumber(3) || hasNumber(3)){
            result += "Fizz";
        }
        if (timesNumber(5) || hasNumber(5)){
            result += "Buzz";
        }
        return result.isEmpty() ? String.valueOf(number) : result;
    }

    private boolean hasNumber(int i) {
        String value = String.valueOf(number);
        return value.contains(String.valueOf(i));
    }

    private boolean timesNumber(int i) {
        return number % i == 0;
    }
}
